The l() function can be used anywhere that php can be used within Drupal. That means from within any module, within template.php, or any include file that gets called by a module or theme. It basically is just a replacement for doing something like this:
$output = ”.$some_dynamic_content_here.”;
Using l() insures that the link starts from the correct context (starting from the base path) and it adds active classes and other information that you wouldn’t want to have to calculate on your own.