From
todayifoundout.com:
"The exact origin of the phrase is not completely known, but general consensus traces it back to the 1950s in the United States and literal cans of worms. Fisherman used to buy sealed metal cans of earthworms, as opposed to the plastic containers or Styrofoam cups of today. After arriving at their fishing spot, they would set the metal can down and open it. What was inside was alive and if the top was left open for too long or the can was tipped over, well, your biggest problem would no longer be catching fish. It would be catching your bait that’s wriggling away."