in reply to Bug in perl?

Is it possible that you're so low on disk space that you're just hitting the wall when reaching line 2048 ?

You'll probably have to first try to decide if it's a problem with the input file or something wrong when it comes to output.

Try to also print to STDOUT just to verify that the problem is rather with the input then with the output:
my $line_number = 1; while(defined ($line = <INPUT2>)){ print $line_number++, ": ", $line; print DEBUG2 $line; }
Do you see all the lines or would the numbering stop after 2048 ?
Do you see that the 2048: line is the last ?