  We study the function $\Delta_k(x):=\sum_{n\leq x} d_k(n) - \mbox{Res}_{s=1}
( \zeta^k(s) x^s/s )$, where $k\geq 3$ is an integer, $d_k(n)$ is the $k$-fold
divisor function, and $\zeta(s)$ is the Riemann zeta-function. For a large
parameter $X$, we show that if the Lindel\"{o}f hypothesis is true, then there
exist at least $X^{\frac{1}{k(k-1)}-\varepsilon}$ disjoint subintervals of
$[X,2X]$, each of length $X^{1-\frac{1}{k}-\varepsilon}$, such that
$|\Delta_k(x)|\gg x^{\frac{1}{2}-\frac{1}{2k}}$ for all $x$ in the subinterval.
If the Riemann hypothesis is true, then we can improve the length of the
subintervals to $\gg X^{1-\frac{1}{k}} (\log X)^{-k^2-2}$. These results may be
viewed as higher-degree analogues of theorems of Heath-Brown and Tsang, who
studied the case $k=2$, and Cao, Tanigawa, and Zhai, who studied the case
$k=3$. The first main ingredient of our proofs is a bound for the second moment
of $\Delta_k(x+h)-\Delta_k(x)$. We prove this bound using a method of Selberg
and a general lemma due to Saffari and Vaughan. The second main ingredient is a
bound for the fourth moment of $\Delta_k(x)$, which we obtain by combining a
method of Tsang with a technique of Lester.
