Script to enter text in a box
Rather than using System Events to generate keystrokes, consider using TextEdit itself to insert text.

tell application "TextEdit"
    activate
    tell first document to set its text to its text &amp; "Hello World!\n"
end tell


There is a difference, though: this version always appends "Hello World!" to the end of the document, rather than wherever the cursor happens to be.  (Unfortunately, TextEdit's AppleScript dictionary mentions nothing about cursors.)

A side benefit of this approach is that you don't have to grant permission to use Assistive Access to your script.