and when heat flows out of the system, its entropy decreases by the same amount. (That is: $\Delta S=+Q_{in}/T$ and $\Delta S=-Q_{out}/T$.)
Imagine what happens when 40J of heat flows from an object of temperature 250K to one of temperature 200K. The warmer object loses entropy because heat flows out of it, but the colder object gains more entropy than the warmer object loses, and so the net change in entropy is positive. If heat were to flow from the colder to the warmer object, on the other hand, the total change in entropy would be negative, and this is not permitted by the Second Law of Thermodynamics (barring some outside influence, such as a refrigerator).
Since thermal energy is usually created by the flow of heat, it is associated with a higher entropy than other types of energy. This is why the Second Law says that heat engines can only convert some heat into work; the waste heat is necessary to get rid of the excess entropy. This is also why we are encouraged in our daily lives to turn lights and electronics off in order to “conserve energy”: obviously energy is always conserved, but what isn’t is “useful energy”, and the less heat flow a process can generate, the more useful energy is available for other uses.