I don't remember where I learned this, but I've always believed that knocking on wood originated from knocking on trees after making a seemingly boastful statement, in a way of asking a trickster god who dwelled in the trees to not punish the person for the statement. For example, if someone said in a conversation, "I've never broken a bone in my body.", they would knock on wood (tree) so the trickster would not cause them to break a bone for being boastful. That's what I've always thought anyway.