I hope I understand your question. If you want to add class to l(), then it must be an array, so your "$link=..." line would read
$link = l($output, $element['#href'], array('attributes' => array('class' => array('YOUR_CLASS_NAME')), 'html' => TRUE));
You can also read more and see other examples in Drupal's l() documentation
Hope this helps.