That is Javascript so you need to put it inside a <script> tag itself.
<script>
document.getElementsByTagName('head').item(0).innerHTML+="<script type='text/javascript'>alert('Test');</scr"+"ipt>;
</script>
However, the code you posted is just equivalent to this:
<script type='text/javascript'>alert('Test');</script>
So you can just put that instead.