I've never used replace_body_all but I've done something similar using subt_body. One of the issues I've encountered is that you need to explicitly match line feed characters \n. Also in your replacement you need to include a carriage return and a new line at the end \r\n or they'll end up on one line like you're seeing.
replace_body_all may behave differently so this advice might not apply.