the problem is that every time the while loop is entered you append $sreenname_count to $screenname... so what you actually have is
$screenname = 'screenname';
$sreenname_count = 1;
then you append count to the name getting
$screenname = 'screenname1';
and then you update the count and append again...
$screenname = 'screenname12';
and so on
you either have to strip the count from the screenname every time you go into the loop or change
addslashes($screenname) to addslashes($screenname.$sreenname_count)
and change the body of if(isset...)) to
$screename_count++;
$inuse = false;
(don't update screenname)