On planet earth, food spoils for several reasons:
- Oxidation
- Dehydration
- Microorganisms
Oxidation is a reaction with the oxygen in the atmosphere. You can witness this when you cut an apple in half and leave it. It will only take minutes until the cuts become brown. Oxidation is usually harmless, but often gives the food an unpleasant texture, look and/or taste. In the vacuum of space there is no oxygen, so by storing food in space, oxidation can be prevented.
Dehydration is when food loses moisture to the atmosphere. It becomes dry and stale. This often does not affect the nutritious value, but gives most kinds of food an unpleasant texture. Food dehydrates because its own moisture is higher than the moisture of the atmosphere. The moisture of space is 0, so being exposed to vacuum greatly increases the dehydration process. However, some kinds of food can be rehydrated by adding water.
Of all the kinds of spoiling mentioned here, microorganism growth is by far the most harmful one. It is practically impossible to produce food in a completely sterile way. Any food product will have smaller or larger traces of bacteria or fungi ("mold") on it or will get contaminated with these during transport and storage. In small quantities, the human body can deal with ingesting them. In fact, most of these organisms themself aren't even toxic. But when the environment the food is stored in is beneficial, these organisms will procreate. They will consume parts of the food and turn it into chemicals which are often toxic to humans (see "Mycotoxins"). However, almost all of such microorganisms require a pressurized atmosphere. In vacuum, they either die or become dormant. That means storing food in vacuum is a great way to preserve food from mold and bacteria.
tl;dr: Food in vacuum of space will dry up immediately, but when you don't care about that, it will be preserved really well.