You shouldn't need to use the Content-type line before each Javascript call, or at all in fact -- the <script> tags should do exactly what you need.
Sometimes I find that when including javascript in perl-generated html, I forget to escape things properly in the javascript functions. Have you tried viewing source on the generated page to verify that you're getting what you think you are?