New lines are not escaped, probably the tests that you are using is printing the output in some other format. Here are two examples that you can try:
FROM alpine
ENV FOO="Hello\nWorld!"
CMD ["sh", "-c", "echo -e ${FOO}"]
and
FROM alpine
ENV FOO='echo -e "Hello\nWorld!"'
CMD ["sh", "-c", "$FOO"]