I wrote that your rename code was wrong that lyrname.name and newName were undefined in you code.
I wrote I had no idea why you made the layer kind a text layer then resterized the layer to a pixel layer when the layer had not content that could be rasterized. The layer is empty.
If you leave out the two statement:
newdoc.kind = LayerKind.TEXT;
newdoc.rasterize(RasterizeType.ENTIRELAYER);
the result may be identical for most likely the layer kind would default to be a normal pixel layer.
I know I do not write well but your reading thing into what I write from far off OZ.
You add 5 layers that the user names via a prompt. The script will only retain the name of the last layer added in var lyrname and have the newdoc layer object to work on the last layer. IMO the script shows you have no idea as to what you are doing.
I solve it, I should have called the artlayer name.