You don't write production code unless there is a need for it.
The need is documented in a failing test case.
Where does the failing test case come from?
Hopefully from some other part of the code needing that code to be there. Or are you just conjuring up test cases out of thin air? If you're doing that, I'd venture you're not doing TDD.
And certainly doing a spike to get the lay of the land is very mach part of XP where TDD came from.
As is slicing your system vertically, so complete units of functionality within an incomplete system.
Rather than slicing horizontally, which is what you seem to be doing.