The term debugging is widely attributed to the early days of computing when computer hardware consisted of electromechanical relays with magnetic coils which attracted moths. Every so often computer engineers would have to clean all the moths out of the hardware in order to prevent the associated computing errors from occurring. See this article which describes the origin of the term in more detail.