If you must store the attachmenst when you read them, then it's pretty simple - you have to do what Windows Explorer does for you:
Check if the file exists.
If it doesn't, write it.
If it does, read all the files which match yourfilename + " (" + number + ")".
Find the highest number
Increment it by one, and try writing your file as that.
You will end up with:
MyFile.txt
MyFile (1).txt
MyFile (2).txt
...
If you don't do this, then your code will just overwrite each file as it comes in.
Other alternatives include not to keep the attachments in files, but to keep them in a database instead, or to keep each message in a separate folder, together with it's attachments.
Personally, I would keep emails and attachment details in a database, and store the actual attachment files under a temporary name in a folder specifically for that.