change file.close() to file2.close() at 157