I'm not happy with the 'hack'/duct-tape solution, but this is how I'm currently solving the problem:
function fix_template_variable_tokens($template_string)
{
$pattern = "/%7B%7B(\w+)%7D%7D/";
$replacement = '{{$1}}';
return preg_replace($pattern, $replacement, $template_string);
}
$html = $doc->saveHTML();
$html = fix_template_variable_tokens($html);