in reply to Open: Invalid Argument

Your post is too long for me to want to read it all at this time of the day, but I noticed the line below:

open(COMPLIST, "> " . $CompFiles) || die "Can't open $CompFiles: $!\n" +;

and I don't know if it would make a difference, but you have and are recommended to use the three args form of open nowadays:

open my $complist, '>' , $CompFiles or die "Can't open $CompFiles: $!\ +n";

(I also used a lexical fh and low precedence C<or> which allows me to remove parens.)