fixing apparent file descriptor leak that shows up after running for a long time.  Creating temporary file using mkstemp requires os.close(fd), surprisingly.