Replace your cursor query with the following, first you test your query then put for cursor, I have not yet tested your all lines of script.
SELECT @UserName = NAME FROM sysusers WHERE issqluser = 1 and (sid is not null and sid <> 0x01) and suser_sname(sid) is NOT null ORDER BY name
You may backup uses using Generate Script from SQL Server Management Studio and then apply script to newly moved database (same or new server).
if I did any mistake let me know.
Shamshad Ali.