I'm trying to do this very simple Applescript for text manipulation.

It runs from the service menu, in some applications. Questions:
- What's wrong with my script?
- Sometimes it shows up in the services menu and sometimes it doesn't. Any advice on this?
My goal is to do this with pure Applescript, but this first step is the hard one.