Changed print(string, file=file) to file.write(string). Removed obsolete deleting files.