Use tag->slug
instead of tag->name
.
Spaces and special characters will be replaced by dashes but altering that is easy:
echo str_replace('-','_',$tag->slug);
Reference
http://codex.wordpress.org/Function_Reference/get_the_tags
http://php.net/manual/en/function.str-replace.php