As far as the coding goes, he'd be far better advised to try:
$basename='/path/to/file/filename';
for ( $playno=1; ; $playno++; )
{
$userfile=$basename.$playno.'.txt';
if ( !file_exists($userfile) )
break;
}
$fp=fopen($userfile, "w") or die( ...
Most particularly, the term "flag" is a 4-letter word as far as variable names are concerned: it simply doesn't convey any meaning. But looking even deeper, the whole approach is flawed if he's anticipating a significant number of users--not just X times through the loop, but X directory lookups, is going to kill performance at some point. This problem most likely really needs (or will soon need) a database...