Try this:

Code:
use strict;
use warnings;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
print "Content-type: text/html\n\n";
my $dbfile = "data.txt";
my $newline = "aaaaa";
open DBF, "<$dbfile";
flock(DBF, 2);
read DBF, my $data, 1000000;
close DBF;

open DBF, ">$dbfile"; flock(DBF, 2);  
 print DBF $newline, "\n" . $data;
close DBF;
exit(0:
For test, just change aaaaa to bbbbb etc.

Hope that helps