As soon as you hear the news, intend to write a sympathy/condolence note without hesitation. This isn't something to put on the back burner. People need to hear from loved ones and associates during this time more than any other. You can pick a nice piece of stationery or buy a card with the words already printed, but plan to send something immediately.
Beginning with the usual, "I'm so sorry to hear about your loss," is perfectly acceptable. However, adding something personal often means more to the person receiving the note.
Write a sentence or two about a memory you have of the deceased, even if you didn't know them well. For example, "I will never forget your mother's smile. She always treated me so well." Or something like, "Your Uncle Joe was the best fisherman. I know it brought him so much pleasure." The more personal you make it, the better. People want to remember their loved ones, and not erase their existence.
If you did have a more personal relationship with the family, your memory can be more detailed such as, "I will never forget the day we spent in the park when the dogs kept grabbing our frisbees. Your dad's laugh was contagious!"
Ending the note with something inspirational is a nice touch. It can be as simple as, "My thoughts and prayers are with you during this transitional time." Or "I will include you and your family in my thoughts and prayers." Many are comforted knowing that "When I see the brightest star in the sky, I will know it is your loved one watching over you."