Adding code to write to output file.