Close the file after writing