Most likely, you have a vacuum leak somewhere. When the load changes on the engine while driving it causes a loss in vacuum pressure which is why it randomly switches around then comes back.
Check this thread fan only blows out defrost
for a diagram of the vacuum line, then check each connection for any split hoses. When a hose breaks completely and falls off it will cause your air to only blow out of the defrost