Maybe you can do this?
if ( !preg_match("<!-- UserID: {$member_id} -->", $readz)){
$nlistz = explode('|||',$readz);
if(count( $nlistz ) == 20){
array_shift($nlistz);
$newlistz = implode("|||",$nlistz);
$beonline_file = fopen($storage, "w+");
fwrite($beonline_file, $newlistz."|||<!-- UserID: {$member_id} -->".$user."|||");
fclose($beonline_file);
}else{
$beonline_file = fopen($storage, "a+");
fwrite($beonline_file, "<!-- UserID: {$member_id} -->".$user."|||");
fclose($beonline_file);
}
}