With steps 5 and 6 you're, as Bruce is also noticing, mixing up two separate challenges. You don't need to do any of the _acme-challenge TXT DNS stuff to get your key authorization to use with the http-01 challenge.
Also, when trying to get help with a programming issue, it's usually helpful (or even required on some fora) to have some standalone proof of concept of the code you're working with. I.e.: it should do everything for the task at hand, but nothing more than that.