One can have thoughts, even heretical thoughts or impure thoughts, while in the state of grace and remain in the state of grace. What is important is what one does with those thoughts. Nourishing, justifying, and enjoying evil thoughts is what could lead to the loss of grace in the soul.
Might a devil have put an evil thought into your head counting on ignorance to allow that thought to fester and grow until you had lost the faith? No one can know, but the question is irrelevant. What is important is that you discussed the issue with others, was put onto the right track, and can defeat the heretical notions. For that I would thank my guardian angel who probably prompted you to seek the opinion of others.
Of course it is best to confess this to a true priest. Every examination of conscience I've ever seen asks, "Have you doubted an article of faith?" or "Have I questioned a doctrine of the Church?" or similar words. Let the priest judge the matter of your soul. That is what he is trained for and is given the graces of the priesthood to do.