LLVM : failure on output stream

   I am creating a custom PreprocessorFrontendAction. In my ExecuteAction
function, I am using the following code:

CompilerInstance &CI = getCompilerInstance();
raw_ostream *OS = CI.createDefaultOutputFile(true, getCurrentFile());
if (!OS) return;

    This is resulting into the following error : " LLVM Error: IO failure on
output stream". When I run clang on a code using "-frewriter-includes", it
doesn't result in any error. The above code is taken directly from the
source code of RewriteIncludeAction. Why is it giving an error? How can it
be resolved (it's working using clang's -frewrite-include command)