COPY TO statement in postgres outputting double backslashes
It doesn't matter how you got the string into COPY TO.  The output of COPY TO is defined on its own terms.

Read the "Text Format" section of the docs for the command you are using.

The output of COPY TO is not inside the dollar quotes strings, so the rules of those strings does not matter.

You can use with (format csv); option to COPY.  It will consider a different set of characters to be special, and will escape those special characters in a different way.  It will not double the backslashes, but might do something else you don't like instead.