in reply to readdir and print file issue

The only explanation I can see is that the omitted code changes @parents and/or %parents.

By the way, are you sure @parents contains a subset of the keys of %parents? If you didn't care about order, you could do

foreach my $parent (keys %parents) { print FILE_OUT $parents{$parent} . "\n"; }