The villain part comes from a joke in one of the episodes. Essentially, Starlight Glimmer went back in time to change a critical event in the past, and the audience sees multiple outcomes where Nightmare Moon wins, Queen Chysalis takes over, then a montage of various other bad guys winning. Flim and Flam were just a joke thrown in during that.Wait a minute are Flim and Flam really villains I thought they were just scam artists?
They started off as legitimate sales ponies though. They just tried to make a low quality product to win a contest, and were run out of town in their first appearance.