I've been making Yogurt and Coconut Yogurt for a long time. I've always wondered why one can't leave milk out for more than an hour or so without it going off, yet when adding cultures or probiotics all of a sudden this isn't a concern.
The initial heating of the milk, besides denaturing proteins to improve the texture, also pasteurizes the milk.
The culture needs to be added in a high enough concentration to crowd out harmful bacteria that might exist.
That said, if your tools or containers are dirty or if your starter is dead, or you don't add enough starter, your yogurt can grow accidental bacteria and go off.
As Bob1 commented, this applies to the first few hours of fermentation before the milk has become acidic enough to inhibit other microbes.
Note that the milk you take out of the fridge has been sterilised (UHT or pasteurisation) - it doesn't have any bacteria (etc.). It also isn't very acidic or salty. This makes it a wonderful breeding ground for anything that can get in - there's no competition. Yoghurt (and cheese, and varieties of ham and salami, and...) is full of a bacterial cultures that are very prolific in that environment, which makes it very hard for any new culture to get established.
Most of the methods of preservation humans had in the past have been based on this; salting, fermentation etc. Either you make the environment too harsh for bacteria to live in (too salty, too acidic, too dry etc.), or you promote the growth of harmless bacteria. Lactic bacteria have been our best friends ever since we started preserving food - they're harmless and extremely prolific, drowning out most harmful bacteria, especially if you help them with a bit of salt or a somewhat acidic environment.
You can even buy bacterial/yeast cultures that you can add to pasteurised milk to make your homemade yoghurt drink (kefir). A popular choice is the so-called tibetan mushroom (a mix of lactic bacteria and various yeasts). The product is full of bacteria, but they're not only harmless, they actually digest lactose, which allows even lactose intolerant people to ingest dairy products without harm. Most of the easy sugars have been converted to lactic acid, which in addition to the massive lactic bacteria culture means the product is very resistant to the introduction of any harmful bacteria.
As an aside, this mechanism is also the reason why some bacteria, like the botulinum, can still be dangerous - they do not colonise your body, they produce a strong toxin as a side-effect of their normal metabolism, so even a very small culture can make the food toxic. But most bacteria are entirely harmless to humans, and most that are harmful are stopped by either the lactic culture, or the acidity, or the salt (in heavily salted products).
 Note that this varies - in the US, normal milk often uses low-temperature pasteurisation which doesn't sterilise the milk; in Europe, UHT is the standard, and you can keep unrefrigerated milk essentially forever (though the quality suffers after a few months as the fats separate, it doesn't become unsafe to drink).
So first off, when making yogurt hygiene is the single most important factor to successfully make yogurt without giving yourself food poisoning. Your statement about having never had a problem and about cultured yogurt never going off concerns me that your luck will make you cocky about it.
inoculation with a known culture helps by prepopulating your yogurt giving your chosen cultures an advantage, but it’s not a guarantee.
However if your hygene practices are not spotless, you can add dangerous bugs into your yogurt. I have had the misfortune it of being food poisoned by my yogurt.
Please don’t get cocky or lackadaisical about hygene and sanitation.