in reply to Can't copy file

use strict;
use warnings;

close FH; This file handle hasn't been opened.

$outfh is never closed. Make sure you close after you are done writing.

Which is probably why the copy fails, the file is still open...

Also, check to make sure the copy was successful:

if ( ! copy($oldlocation, $newlocation) ) { print "Copy failed: $!\n"; }