Did you say this is in a custom file? If it is, there's no need to use $vbulletin->db->query_first - just use PHP.
But, assuming its not (in all honesty I haven't read all of this), try this..
Code:
$tmpname = $vbulletin->db->query_first("
SELECT email
FROM " . TABLE_PREFIX . "user
WHERE username = '" . $vbulletin->db->escape_string($username) . "'
");
$tmpnamer = $tmpname->row_array();
$usermail = $tmpnamer['email'];
echo $usermail;