This is extremely annoying. 2009 MacBook Pro running OSX 10.7.5. I have an external hard drive connected via USB for Time Machine purposes. This device, and anything else connected via USB, frequently accidentally ejects with the slightest disturbance such as when I brush against the USB cable. It's very extremely annoying. The trouble doesn't come up as often with devices without a cable like flash drives, but sometimes it happens. It happens very frequently with devices connected via a cable. What is going on?
You either have a bad USB cable or a bad USB jack (either on external devices or Mac). I would start by replacing the USB cable on the external hard drive. If that does not work then your USB jack will most likely need to be looked at by an Apple repair center.