in reply to system($cmd) spawns infinitely

and what does it print to the terminal? Do you get thousands of "Environment Check..." messages as well? If you do then you are in a loop, possibly in the code that calls this code (sub?)