40 million tweets from 200k users
Yikes, you're running almost 3,000,000 individual queries.  If you could do 4 a second (and you probably cannot) that is still a day!

How about just

select username, tweets from tweets order by username


Then of course you have to do some fancy footwork to switch from one file to the next when the user changes.

It should only take a few hours to run.