First I think you spelled this wrong. It should be scriptTag.text(this.val());
I think your issue goes deeper than that. It is my understanding that when you inject a script tag into the dom it gets evaluated immediately but you are waiting to put the actually code in AFTER it has been already added to the page. Reorder it.
scriptTag = $("<script type='text/javascript'>" + this.val() + "</script>")
.appendTo($('iframe').contents().find('head'));
Note I had to bring out the selector contents because it was in the scope of a different function.