Someone told me if there's food under my bed and I sleep in the bed I can't use the food because it becomes tamei. Is there a source for this?
Such an idea is found in a passage in Pesahim (112a) which states that a ru'ah ra'ah rests on food and drinks placed under a bed. Elsewhere, ru'ah ra'ah is explained by Rashi as meaning a malevolent spirit. However, Rambam, who did not believe in demons, always omits demon related rulings, or somehow presents them in a non-demonic way. In typical form, omitting mention of demons, he writes in Hilkhot Rotseah Ushmirat Nefesh (12:4) that one should not put a cooked dish under a bed, lest something damaging fall into it.
Significantly, the Yerushalmi Avodah Zarah (2:3) references this idea that it is dangerous to put food under a bed (and seems to likely be the source for Rambam, cf. Ra'avad, Hagahot Maimoniot, Ma'aseh Rokeah, and Beiur of R. Qafih there), but does not specify that the danger is because of demons.
Importantly, as noted by the Ma'aseh Rokeah to Rambam there, according to Rambam's reason (concern for contaminants falling into food), the concern only applies to uncovered foods.
However, the Arokh Hashulhan (YD 116:11) states that people are not generally stringent with this.[i] Similarly, the Binat Adam (Issur V'heter 63 (82)) emphasises that people are not generally careful with this, and writes that perhaps it is not a concern once people don't worry about it (d'dashi bah rabbim).
Others are stringent, such as Hida (Shiurei Berakha 116) quoted in Yabia Omer 1 Y.D. 9:22 (who cites others who share that view), and R. Elijah of Vilnius quoted by Binat Adam there (although we do not know if this was a personal stringency, or a universal ruling of his.))
Whether one attributes this to demons, or to other damaging things that might end up in your food left in an unsanitary place, the problem described is not strictly speaking one of impurity. Nevertheless, later sources often compare or conflate various non-physical dangers (as our case may be), as does R. Abraham Schor in Torat Hayyim to Shavuot (15b) who uses the term 'impurity' in the context of demons.
Lastly, it should be clarified that neither the Bavli, nor the Yerushalmi, nor Rambam (nor the Tur YD 116, nor the Shulhan Arukh YD 116:5) limit the halakha to a case where someone slept on the bed while the food was under it. Nevertheless, Yabia Omer (YD 1:9:5) cites R. Hayyim Palagi (Lev Hayyim 1:66) who infers from the Torat Hayyim to Shavuot, that the concern is only where one slept over the foods.
[i] It could be understood that he means that people are not careful with raw food in particular, but I don't think that is his intent, particularly given the fact that he is clearly basing himself on the Binat Adam.