Mixing Reads and Writes may be what you're looking for, although you could do two separate passes (one read, and one write). You want to read the file first and only write the information if the username is not found there. Your 2nd example includes most of the code for doing the reading, and your 1st example is code for doing the writing.
For your 2nd example, you need to change the last to last if $userverified. As it is, you're immediately exiting the while loop on the first pass. You could change the comment, too, to exit the loop, which is a little more accurate.
The PerlMonk tr/// Advocate