There is nothing inherently wrong with writing "Thank you" in a comment. It would be preferable to thank good answers with an upvote and the best answer by marking it as accepted. If on top of all that you also want to post a "thank you" comment, that's nice (I guess).
However, a comment saying just "thank you" isn't really what comments are for, and if you post one, it will likely be deleted as too chatty:
When should I comment?
You should submit a comment if you want to:
- Request clarification from the author;
- Leave constructive criticism that guides the author in improving the post;
- Add relevant but minor or transient information to a post (e.g. a link to a related question, or an alert to the author that the question has been updated).
When shouldn't I comment?
- Compliments which do not add new information ("+1, great answer!"); instead, up-vote it and pay it forward;
You have quite a few other ways of being nice, to everyone not just the person who answered your question:
- Ask helpful questions,
- Post great answers,
- Upvote helpful posts,
- Downvote unhelpful posts,
- Flag content that doesn't belong,
- Revise posts,
- Post comments with relevant feedback,
- etc.
The list of things you could be doing that are more helpful than a simple "thank you" comment goes on ad infinitum.
See also: Thanking users who answered my question