Need to return a string as permalink insted of str_replace

Use get_term_link() to get the correct URL for a taxonomy term archive.

$list .= "\n\t\t" . '<li><a href="'. get_term_link( $tag ) .'">'.$name.'</a></li>';