I used to get out of breath when cycling, running or swimming and a friend mentioned that it is important to fully breathe out when feeling slightly out of breath, as it is due to a build up of carbon dioxide in the lungs, rather than a lack of oxygen. Is this true? I have found that her advice works and I rarely get out of breath now, but I've been trying to find scientific literature to better explain why this is.
This is a huge topic. It is true that the breathing reflex is controlled by CO2 in your body (not just in the lungs). The key is the acidity of the cerebrospinal fluid. If you reduce your CO2 level, you will not feel you need to breathe that much but that does not make you to have more oxygen for your exercise. So you will not be faster.
Divers know how to reduce the need for breathing by hyperventilation. That reduces the CO2 content in the body even if it does not raise the O2 level too much. This makes it possible to hold your breath longer. The danger is that you may actually pass out due to insufficient level of oxygen even if you are a few centimeters below the water level. If there is no one to save you, you will die.
To actually get faster, you need to get enough oxygen into your lungs and then your VO2max determines how much you are able to use for your activity. VO2max is the maximum amount of oxygen (measured in volume of O2 per kg of body mass and a unit of time - ml.kg⁻¹.min⁻¹) that your body is able to use for an aerobic activity. It determines the power your body is able to deliver aerobically - that means in a sustained effort, not in a short sprint. Top athletes have values of VO2 max reaching 90, normal people will have smaller values depending on their fitness, their age and their sex. There are many explanations on the internet and also tables of values telling you how good you are with a certain value for your age and sex.
Menaspà, Sassi, Impellizzeri (2010) https://doi.org/10.1249/mss.0b013e3181ba99bc
Just getting rid of the CO2 will not let you produce more power. Also, quite obviously I think, if you do an effort that is hard enough, you will be out of breath no matter what you do. Just observe professional athletes after they cross their finish line.
I'll post an alternate take on the question.
In exercise science, there are two notable ventilatory thresholds. VT 1 is the level of effort where breathing rate begins to increase noticeably. You won't be able to give a speech comfortably. You will need to talk in short bursts. I think that VT 1 in cycling onsets at about endurance pace, maybe 55-60% of your threshold power (for those not familiar, that's your maximum sustainable power, you're mainly producing aerobic energy, your blood lactate levels are about stable).
VT 2 onsets at a higher power level, when your blood lactate levels are elevated. I think that VT 2 typically onsets around threshold power. Speaking is difficult. You should be able to get a few words out at most.
I'm not sure what ventilatory threshold the OP was at, since we can't observe them directly. I'm not sure their friend's advice was correct, however. Untrained individuals will hit both ventilatory thresholds earlier than trained individuals, possibly much earlier depending on their base fitness. So, if the OP was untrained and trying to keep up with a friend, even if the friend wasn't that fit, their cycling-specific fitness might still have been a lot higher than the OP.
Exercise technique may also part of this. When I was first starting to run in my early teens, I couldn't modulate my power well. That is, I could only run hard or walk - in part beacuse my neuromuscular system was also first adapting to the movements of running. I had the same thing with swimming in my late teens, and I probably still have some of it because I don't swim often. I don't believe I experienced the same thing when I started cycling, but my base fitness was high and cycling isn't as technique intensive as swimming. In short, if this was the issue, then I think the only solution is to persist until you are used to the sport and you can modulate your power well. If you had gross errors of technique, you would want to correct those, and I think this would affect swimming more than cycling or running.