The only thing that makes sense to me is that $text
immediately after this line:
$text = force_balance_tags($out);
Has something that wpautop
translates as a paragraph break– something like a double newline.
Untested, but I would think that trim
would clear it up.
$text = trim($text) . $excerpt_end;