Most overdoses could be avoided by knowing exactly what you're taking, at what dose, and maybe even under supervision (like at safe injection sites; places that have gone years without a single person dying on premises).
The homeless people thing is a failure of our healthcare and housing systems.
Fentanyl only exists on the black market because drugs are illegal. Fentanyl is kind of a shit high compared to other opioids, it's only a problem because dealers are cutting their illegal drugs with it.