If you look at that PDF again you will see that you copied an Illustrator script. Each app has it's own Object Model. There are some overlaps but you are better off using the Photoshop JavaScript Ref.PDF for the Photoshop Object Model. For example Photoshop layers doesn't have an add method, only artLayers and layerSets have it. And Photoshop doesn't have a textFrame class. Instead it has artLayers with the kind property set to LayerKind.TEXT.
Here is how you could do the same thing in Photoshop.
var myDoc = app.documents.add();
var myLayer = myDoc.artLayers.add();
myLayer.kind = LayerKind.TEXT;
myLayer.textItem.contents = "Hello world!"