in reply to filename flagged as Invalid argument

I would be suspicious of your definition of $file and $filename.
my $file = 'SyncItemMaster.xml'; my $filename = 'Hashstructure.txt';
is more what I would expect to see, though I am unfamiliar with what you are trying to do...