For most of the past 70 years, the federal deficit has been strongly counter-cyclical. That means when the economy goes down, deficits go up. After all, in bad economies, tax revenue falls as people and corporations make less money. Government spending also usually rises. Some of this bump in spending happens automatically as people become poorer and qualify for government services (unemployment benefits, food stamps); some of it comes from deliberate, one-off stimulus measures.
In a recent client note, Goldman Sachs Economic Research put together the following chart, which shows budget deficits or surpluses (expressed as a share of the economy) tracking unemployment (inverted here, to make the trends easier to see).