It's not mysterious. Coffee has been around over 500 years, and modafinil was discovered less than 50 years ago. Most people haven't even heard of modafinil. Plus, coffee tastes good.
1) We've banned a lot of dangerous drugs that have been around for centuries. Opium has been used since at least 1500 BCE, so over three THOUSAND years.
2) I think coffee tastes awful and can't even stand the smell. So maybe I'm biased. :)