Why don't you use tail to get the last line, compair that, then if you need to alter it (I recomend using nl to get the number of lines) use head with the number of lines - 1 plus your line.
eg.
perl addline.pl -f test.dat
# Get the file through get opt
my $line = `nl $file | tail -n 1`;
my @items = ($line =~ /^\s*([0-9]+)\s+([0-9]+)\s+/);
my $lineNum = int($items[0]) - 1;
my $newDate = $items[1];
my $fileTmp = $file . ".tmp";
if($date eq $newDate){
system("head -n $lineNum $file > $fileTmp");
system("echo $newline >> $fileTmp");
system("rm $file;mv $fileTmp $file");
}
I haven't compiled this, but you should have an idea of how this works.
ps. if you're doing this on windows, download cygwin and use the nl, tail, and head that they have in their packages. (They are exes, and will work with system.)