in reply to delete file

Have you looked at what $! contains? Also, are the files still held open?

for my $file (@files) { unlink $file or warn "Couldn't remove '$file': $!"; };

Maybe the path to these files is not valid anymore because you changed the current directory?

Also see File::Temp for creating and managing tempfiles.