Well written good guys are rare. Well written villains are still rare, but not as much as well written good guys. Villains are easier because they are PERCEIVED to have more narrative freedom, and, as has been mentioned, we project all of our doubts and misgivings with acting proper upon them. They fascinate us because we are constantly imagining having the freedom/audacity of being them. We do this with heroes, too, but, like I said, genuinely interesting ones are hard to come by, and even well written good guys are generally familiar.
That's some narrative reasons. The underlying reason is original sin, which is pride/vanity. I'll spare you the religious explanation, so here's the more secular conceit: human beings tend toward selfishness and vanity without outside forces like universal standards of morality and structure to guide/coerce/force them into more cooperative states of mind. Villains buck the system. They are almost always confident, put together, comfortable with themselves, and otherwise perfectly satisfied with their flavor of evil. But regardless of whether or not they are well intentioned or truly malicious, ALL villains act the same--they are convinced that they know better than anyone else, from you to God to anything else you wish to add. Their pride gives them licence to do as they wish. They know better, their moral compass is right, they have the answers, they have the knowledge to make the right decisions.
We love that. Many people have brought up this point: villains allow us to live the fantasy. We hunger for that complete freedom--from social constructs, from expectations, from accountability, from moral standards, from law, from virtue, from God. The story of Lucifer is the quintessential heart of all villains: I know better, so I will do as I wish.