Those are actually warnings - the script keeps running, and probably does what you intended overall (whereas an error would cause the script to halt immediately). I expect that the warnings happen on the last iteration of the "for" loop:
for $line (<FILE>) {
The part in parens produces an anonymous array that the "for" will iterate over, and the last element of that array the "undef" element from the last attempt to read from the file handle and encountering 'eof'. If you used a while loop instead, you wouldn't enter the block (lines 25 and 26 would not be reached) on that last attempt to read from the file.