Close file pointers before renaming the file.

File pointers must be closed before renaming the files. On some platforms
it's not necessary, but it's a good practice.

Signed-off-by: Niko Rosvall <niko@ideabyte.net>