I don't know why bad things happen to good people. However, in my current lifetime I have noticed something very interesting:
Yes, bad things happen to "good" people. But bad things also happen to "bad" people.
Good things happen to "good" people. And good things happen to "bad" people.
It makes me think of that Bible verse about it raining on both the just and the unjust.
Sometimes it seems like Karma totally works... and sometimes, if I'm honest, it seems like Karma feel asleep at the wheel. (Hahahahaha, get it? A wheel is a circle.. karma is the idea of what goes around comes around...hahahahaha. Hey, I found it verrrry clever.)
Anyways, the point I'm getting to is this - I could say that you should be thankful, because if you're thankful you'll set yourself up for more good things to happen to you. Truth is, I can't guarantee that. What I can say is that having a thankful heart will enable you to see how much good is already in your life and will keep you in good shape for noticing the good things that'll happen to you in the future. Likewise, if you're not thankful for what you already have, you'll be more inclined to pay the most attention to any negative things that happen to you in the future.
It goes along with that saying about money not buying happiness. After all, it's never about what you have, what your relationship is like, or what your health is. It's always about how you perceive yourself based on what you have, how you see your relationship, how you feel about your health. Ya know - perception is the ultimate reality, it's all relative, etc, etc, etc.
*Not to say it doesn't suck to be poor, lonely or sick - I'm just digging a little deeper than those surface symptoms.
Basically, I just don't think that gratitude is a magical formula that brings good stuff your way. I think gratitude is like a good pair of contacts or glasses that puts things in better focus.