It doesn't take you to your perl file because dooutput() exits the script, and you don't want that.
You need to change that line to:
Code:
eval("\$photogallery = \"".gettemplate('photogallery')."\";");
But that's not enough, because a location header TAKES you to the file, doesn't INCLUDE it. And sorry I can't help you from here because I know very little about Perl.