Are these three independent snippets, or does your main script actually look like that? Because the problem I'm having with it, is that here, you appear to continue onwards with the next step, even though execution of the script should have stopped here. It doesn't make any sense to fill in template variables, if loading the template file failed. I think having one huge eval block, containing all of the code, instead of three separate ones, would make more sense.
And perhaps you should have combined these techniques, pushing $@ onto @debuglog instead of printing it out.