I don't know why you needed to do modify this function. This will cause memory errors when there are many rows in the database.

The $purge_count and do while loop was done specifically to solve memory issues by deleting user accounts in batch. At least make the user query get only a certain number of results, and let the process run without being timed out (set_time_limit( 0 )).