Most of the ideas posted above are listed in: Brasch, Rudolph: How did it begin? : customs & superstitions and their romantic origins / R. Brasch. - Longmans, Green and Co. Ltd, 1965. New ed.: Sydney : Fontana, 1986. - ISBN 0-00-636898-0.
I only have the German translation. Here an abstract: Touching wood is a superstitional use to avert the turning of luck for persons or things spoken about. - 1. Usual explanation: touching a piece of the Holy Cross shall keep the good luck. - 2. Knocking at the church door and asking for asylum put the supplicant under protection, nobody and nothing could harm him any more. - 3. When people lived in wooden houses, they knocked at the (wooden) walls so the bad spirits couldn't hear when somebody talked about his good luck. - 4. The usage is possibly older; in heathen times people believed that the powers of the God entered the tree struck by a lightning. E.g. God of Thunder was housed in oaks. To touch its wood would bestow the magical powers to the person doing so.
In Germany instead of touching wood we knock on wood thrice. (Concise dictionary of superstition. No explanations given)