TextEdit can open documents in plain text and rich text.
To test this you can open three documents and make one plain, two rich. In the second one make text colored and copy / paste it into the other two documents.
Once you’re sure you have things sorted, repeat the copy and paste ...
Debugging these jobs is much easier with a gui like https://www.soma-zone.com/LaunchControl/
Here is another thread with tips on debugging agents and daemons.
In a nutshell, add keys to redirect STDOUT and STDERR to files you can tail.