I couldn't understand this part. 
1. Generate file name
2. If does not exist already, break
3. If the file does not exist, clear the buffer filename

And this is in an infinite loop.