I was also having this issue, and your thread was referenced from my thread, wanted to post here in case it helped you or anyone else that I've determined the cause in my case was having
app.doAction("action","set");
in the script. If you comment that out temporarily to record it it records fine. There may be other "problem" lines that also trigger this, so if you weren't scripting an action, just comment your entire file, record it as a step, then uncomment it and it should continue to work fine. Unideal, but better than not being able to record it, or having to rearrange your entire file organization to put things in the Presets / Scripts folder.
I can't reproduce this when using File > Scripts > Browse... recorded into an action, it only records the 1 line for the File, without the offending 2nd Name line as per your screenshot.
As the others have commented, you can alternatively install the script into the Application's Presets/Scripts directory and record the installed script from the File > Scripts menu.