I had a similiar problem to what you are describing. What i did was ground the wire by the fan relay (forgot what color, but can be accessed through Gnttypeorg), the fan should turn on. Somehow i was trouble shooting with this wire grounded. I think even though this wire was grounded sometime the fan would not turn on.
It turned out that there is a fan ground also by the rear of the passenger side valve covers. I was messing around with those bunch of wires back there and suddenly the fan kicked on. I used to have bad motor mounts, and this tore the ground wire a little. Sometimes it would make a connection sumtimes it would lose it. This explains why when you shut off the car the fan sumtimes works cause the engine moves a little and makes the ground.
In my situation, sumtimes the fan would be on while car is running sumtimes it would not. i ended up cutting the wire off the harness and grounding it to the back of the firewall and after that had no problems. My digital dash goes buggy sumtimes too. Guess what? It's grounded in the same area.