I just solved this problem using Tie::File. It was the only way I could correctly insert a new line into a file.
In my case I needed to replace the first line.
use Tie::File;
tie @anArray, 'Tie::File', "afile.csv" or die "can't open";
#Deletes the first line in the file
shift(@anArray)...