added the exception handling for output file