Try adding:
return;
under your prints. If that doesn't work trying returning all the output. If that doesn't work try:
return print $output;
return;
under your prints. If that doesn't work trying returning all the output. If that doesn't work try:
return print $output;