I think that prayer does work for some people for a few reasons.
1) Prayer is a way to stop worrying, because you feel you have put it in God's hands. Someone once said that it's not what happens to you that determines your happiness, but how you feel about what happens to you.
2) Prayer is a form of meditation which causes your brain to release serotonin, a feel good hormone produced by the body. If you believe in God and get that feeling by prayer, it naturally validates your belief.
3) Prayer is a way to calm the mind, which then allows the subconscious to come up with a solution to the problems that bother you.
I believe some people are just naturally more prone to get in a meditative state by prayer and get those warm and fuzzy feelings, while others are more naturally sceptical and logical and not get that effect from prayer and so more likely to be non believers. Of course it's not absolute, but I imagine it is a range from strong believer to strong non believer, while also being impacted by upbringing, religion and other factors.
That is why religion is so universal, it does work in a very concrete way for some people, and those people are not going to give up what is for them a very positive thing. I never got much of that from prayer, so it always seemed odd to me when people said that Jehovah helped them, or answered their prayers. I felt there must be something wrong with me, because he certainly never did anything for me, lol.