It was believed gods lived in trees; to ward off bad luck, do this to wood
It is believed by some that the superstition dates back to ancient pagan 
times ... spirits or deities lived in trees, and knocking on the tree or touching it 
would... [DOC] [TLE] Superstitions and their origins: Why is touching wood lucky?