Twig templating within  tag
It appears to be due to the angle brackets. Try:

&lt;script&gt;
    var homepageStandfirstAnchors = [{% for anchor in homepage.homepageStandfirstAnchors %}[{{ anchor.text }},{{ anchor.section.handle }},{{ anchor.anchorLink }}],{% endfor %}];
&lt;/script&gt;