After hitting this same brick wall, I decided it was easier to use ns_httpget to get the formatted html.
I may try your code for my work too.
(caveat: this was done in ACS, not Open ACS. It should work anyway.)