close file before exit