Dogs don't do things out of spite. They don't understand to concept of it. Based on the info you've given it might be medical, might be something that comes with old age. I would take him to the vet and have them check him out. If he's not peeing when you're not home (which are you sure he's not? Maybe somewhere where you haven't noticed?) then I would lean more towards old age, most dogs sleep/relax when no one is around and don't stimulate the bladder, when you are home he's up and about or playing and get's the bladder going.