close file handle before exiting