Actually Cantor was working on a specific problem from the theory of trigonometric series, the so-called uniqueness problem (I cannot be more specific until MathJax is introduced to this site). This problem led him to consideration of arbitrary sets on the real line. I mean more complicated sets than finite sets or finite union of intervals. At that time there was no tools and no terminology to study arbitrary sets, so all this had to be created.
In the process of this study he created not only the set theory but also what is called now General topology. (In is interesting to notice that the original problem about trigonometric series has no complete solution to this day:-)
The original method of proof, the so-called "diagonal procedure" goes back to Cantor's redecessor, Paul du Bois Reymond, who was also studying trigonometric series.