IMHO its all about quality control. The reason fentanyl is used is the suppliers can cut the real stuff (cocaine, heroin, Xanax or whatever) with almost microscopic amounts of fentanyl and a lot of neutral stuff i.e., non-intoxicating filler substances similar in structure and color, and still get the same "kick" out of the material sold — thus greatly reducing the cost of production.
For reference the plant-based opium needed to produce a kilogram of heroin can cost producers about $6,000, while the precursor chemicals to make a kilogram of fentanyl cost $200 or less. Combine this with the fact that fentanyl is 50X more potent than heroin means that a dealer can replace for pennies the same kick of the more expensive heron.
This can be done at different level in the supply chain with each level down to that of the end user not knowing what the ratio of fentanyl to everything else in the mix.
The problem is that it is very easy to misjudge what the prior and subsequent level in the supply chain is doing and very easy to end up with a fatal level of fentanyl.