Welcome to the monastery
Sophienz
At first glance it not seems a behaviour related to flush or autoflush the filehandle and about this (never used) method i read
Turns on autoflush, print ARGS and then restores the autoflush status of the IO::Handle object. that seems also not so efficient while itarating over array.
Anyway as the famous motto says 'Bad data ruins your day' check your array using something like
Data::Dump dump or dd method: is better of the core
Data::Dumper.
HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.