So you have an InfoPath 2007 form that renders as a Web page and you use the userName() function to get the current user. This works fine when you're using Windows Authentication but stays empty when you're using Forms Based Authentication !!
Also note that for Windows Authentication it doesn't return the domain part just username...