The escape is working, except you aren't escaping often enough.
With your code, you must escape twice: once for the SET command, and a second time for the ECHO. The code for the SET has double escapes. Ater execution, the value of test will contain the single escapes so that the ECHO works properly.
SET test=^^<foo^^>^^<bar what="cat"^^>^^</foo^^>
You can get by with single escapes if you ECHO the value directly:
ECHO test=^<foo^>^<bar what="cat"^>^</foo^>
Or if you use delayed expansion:
SET test=^<foo^>^<bar what="cat"^>^</foo^>
You can eliminate all escapes if you enclose the assignment in quotes:
SET "test=<foo><bar what="cat"></foo>"
Bear in mind that in the above example, "cat" is no longer quoted during the assignment, so you would have to escape any poison characters that might appear there.
If you have lots of text to write, then it might be worth using my PrintHere.bat utility that emulates the unix here document feature. Assuming you have PrintHere.bat in a folder that appears within your PATH, then you could use:
call PrintHere :test