Do the close() first to get the data out of the process before the rename.