in reply to rearrange lines in file

Just sticking text in at the beginning of the file will not make the rest of the file move out of the way, your code will need to do the work of moving the other data to make room for the new line. If the file is small enough to hold in memory, this may be an easier randomizing technique:

open(FIN,"<$ARGV[0]") or die "Input file: $!"; chomp(@data = <FIN>); close(FIN); open(FOUT,">$ARGV[0]-randomized") or die "Output file: $!"; while(@data) { print FOUT splice(@data,rand(@data),1)."\n"; } close(FOUT);