My modification to ghostdog74 is that file handle should in the print statements and the file should be closed after the second print statement.
open(FILE, ">", "file") or die "cannot open $file: $!";
print FILE "add line to top";
while () { print $_;}
print FILE "add line to bottom";
close(FILE);