Why are B1 droids in Star Wars made to have personalities? Shouldn't they be programmed to be perfect soldiers?
They’re caused by programming glitches
Basically, it was an accident. The B1 battle droids are indeed intended to be mindless soldiers with little actual personality (beyond "kill this"):
Rather than use flesh-and-blood warriors, the Separatists prefer mindlessly loyal soldiers that are easily controlled. The soulless ranks of their armies are dominated by tall, thin B1 battle droids built as mechanical imitations of their Geonosian designers.
However, it’s quite common for them to develop personalities due to "programming glitches":
Battle droids can be controlled by centralized command centers such as the Trade Federation’s enormous Droid Control Ships, or programmed for independent action. They often suffer programming glitches that manifest as personality quirks.
Note that this is not the case with all droids. Droids meant to operate in social situations are actually programmed with personalities, as also discussed here. However, any droid can also develop personality spontaneously from “errors” in their programming, and for whatever reason, that seemed to be particularly common in the B1 droids. One might also wonder why an R2 astromech unit, whose purpose seems to be navigation and repairs, has a personality. The answer is the same: it’s not programmed in; it develops spontaneously. Sadly, many organic entities seem not to have recognized this possibility….