Run an AppleScript that requires keystrokes while the screen is locked?
No i'don't think you can do this the way you want.


Every Human interaction on a PC during Screensaver tries to deactivate it. (Like moving the Mouse, pressing a Key e.g.) 
Applescript most time is used to Script some GUI (like in your case --> tell application TextEdit -> does nothing other than opening Textedit like you would do it by double clicking)


So to bring you a way which should work:

do a applescript which writes the text to a file directly and then open the file with the text in it if needed.

something like this:

tell application System Events
    do shell script "echo 'your text that you wanna type' &gt; /path/to/the/file/where/the/text/stands/in"
end tell

tell application TextEdit
    open /path/to/the/file/where/the/text/stands/in
end tell