close file after write