Your code is good, you just forgot to call save
:
$string = "<div id='container'><div>im a text node</div><div>im another</div></div>";
$html = str_get_html($string);
foreach($html->find("text") as $ht) {
$ht->innertext .= "<span>end of each text node</span>";
}
$html->save();
echo $html; // echo modified html
Just replace the <span>
element with your $var
.