You could just open and write the last one at the end. This should also fix your numbering problem.
open(INPUTFILE, "$file");
open(OUTPUTFILE, ">$outputfile");
my $counter = 1;
while (<INPUTFILE>) {
print OUTPUTFILE "$counter. $_";
$counter++;
}
close(INPUTFILE);
close(OUTPUTFILE);
If you want to copy over the old file, just do it at the end.
UPDATE: You should probably check to make sure the files actually open (using
die) like you did in your original code.
UPDATE2: Only now does command line register in
krujos' head. Doh!