Modified code to generate an output file.