I'm happy to hear Charlie is feeling better.
Bacteria can be present in the GI for long periods of time without causing trouble. Then, usually in a time of some stress, they can overgrow and cause symptoms. He may have been carrying it all along.
Otherwise, just know that we don't live in a sterile environment. He could have picked it up from food. He could have gotten it from you or another person by accident. We carry some bacteria that don't hurt us that can be opportunistic in them, especially in our mouths. Sometimes, sharing food can transfer it.
In general, there are three ways bacteria can get a chance to infect:
1. If there is exposure to a highly pathogenic (able to cause disease) strain of bacteria. This is not common. An example is the transfer of Salmonella from a reptile to a bird.
2. Overwhelming exposure to environmental bacteria. If conditions are very dirty and there is a build up of organic material (like poop, or fresh food that sits out a long time), then small amounts of bacteria can sometimes multiply to large populations. If the bird is then exposed to this, they may be more easily infected.
3. If there is some other cause of immune-suppression, like an underlying infectious disease like psittacine beak and feather disease, or a metabolic disease, like fatty liver. Even moderate to severe stress can cause enough immune-suppression to allow bacteria to invade. This is why it is so important to thoroughly investigate any infection that is diagnosed. By this I mean to run enough diagnostic testing to become comfortable that there is no underlying problem that allowed the infection to happen.
Watch Charlie closely for any signs of problems and get testing done if there is any sign of anything unusual.