Try putting the $a=1 at the top of your While Loop.