You're not doing anything incorrect. The code you've provided and your example work perfectly for me. Perhaps the bug is generated by the parts in your while loop that you've cut out for the moment.
Obvious things to check
Run the first loop from your post over your test
data and make sure that the results are the same as you're
complaining about.
Double and triple check that your input file only has
28 records and not 28 records followed by some space followed by the same 28 records (it can happen).
I ran your loop, as is, except I added strict. I can't see that making a difference in this case, but it's a good habbit to get in to.