in reply to Re^2: data leak using package
in thread data leak using package

Close the FILE filehandle before you do the rename. Until you close the filehandle, some of the output will be buffered and won't have been written to the disk file. Closing the filehandle will flush the buggered data to disk.

As frodo72 pointed out, you are Suffering from Buffering.