Make sure to close file descriptors after writing.