in reply to problem in for loop

You are trying to access an element which is beyond the last one in your array:
$file_array[$i+3]
You have 20 elements in the array (20 lines in your input), and the last time through the loop, $i=18, but $i+3=21.

Tip #2 from the Basic debugging checklist : add print "$i\n" near the top of your loop.