Within the while loop add
var_dump($menu); and post that. Assuming that the <a/> is a typo just in the forum here, the output you have is consistent with 'cat_name' containing the value
Name</a>\n<a>. So lets start there.
header('HTTP/1.1 420 Enhance Your Calm');