I might be off here, but have you tried to save the output of your script to a file and then open your file through a browser? Doing this will ensure that your script is outputting valid HTML. If it's not, I think it might be easier to debug (hmmm, why doesn't this work...what the hell is a <@#$%!> tag...etc)