Extract the write_file_with_comments methods.