It originated in textile factories that used the Jacquard loom. The loom used punched cards to control the weaving pattern, enabling quite intricate designs to be woven much more easily than was previously possible. But sometimes the program cards were fed into the machine in the wrong order, producing errors in the pattern. Just as today, such programming errors were called “bugs”. A rug woven with a bug in it would often need to be entirely discarded and rewoven. But the discarded rugs were reused for purposes where the pattern wouldn’t matter, such as for an awning on a ship to protect it from bad weather. A ship so protected was called “snug”, and since it was protected by a buggy rug, it would be said to be “snug as a bug in a rug”.
No, the origin of the expression is completely different, but the words were later mispronounced and its meaning changed somewhat. There is a sort of similarity, though: it is about safety in obscurity, about evading capture by blending in ad vanishing in a massive throng. The original version is “snuck a buck in a ruck.”
Heh. Those answers remind me of certain segments on Wait, Wait, Don’t Tell Me.
It had something to do with stoats and Orson Bean, as I recall.
Wrong thread, that discussion should go to

But do they wear plaid?
Does anyone?
no, of course not
Plaid be the bees knees
I never heard of black and yellow plaid.
Well, there we are, then.
Wherever you go, there you are.
That’s what bothers me.
Don’t worry, Buckaroo. It’s OK.
Banzai!
Huzzah for little trees!
So what? Big deal.
I had a long hooded coat almost this color when I was in college (in the late 1970s).
The 70s were known for their wild and crazy color combinations in everything. Fashion, painting, wallpaper, furniture, rugs, etc.