Are you sure your script isn't called with modified ENV already? cron-jobs usually start with a modified aka purified ENV

If not you might add debug code that checks ENV and warns about it. If your script is not multithreaded this should enable you to pinpoint the culprit in a few runs with ever narrower "bisection" steps.