Since you don't really say where you tried adding ExpandEnvironmentVars(), I still cannot rule it out.

Try replacing the line:
$line = ReadLine($arrayfilehandle)

with:
$line = ExpandEnvironmentVars(ReadLine($arrayfilehandle))
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.