Let us start with
$$h(x) = \begin{cases}
\hphantom{-}4(x+2) &, -2\leqslant x < -\frac{3}{2}\\
-4(x+1) &, -\frac{3}{2} \leqslant x < -1\\
-4(x-1) &,
\hphantom{-}\; 1 \leqslant x < \frac{3}{2}\\
\hphantom{-} 4(x-2) &,
\hphantom{-}\frac{3}{2}\leqslant x < 2\\
\qquad 0 &,
\hphantom{-} \text{ otherwise.} \end{cases}$$
For $c > 0$, let
$$h_c(x) = c\cdot h(c\cdot x).$$
Then $h_c$ is continuous, and $\int_{-\infty}^0 h_c(x)\,dx = 1$ as well as $\int_{-\infty}^\infty h_c(x)\,dx = 0$. Now let
$$g(x) = \sum_{n=1}^\infty h_{5^n}\left(x-n-\frac{1}{2}\right).$$
Every $g_n(x) = h_{5^n}\left(x-n-\frac12\right)$ vanishes identically outside the interval $[n,n+1]$, so $g$ is continuous, and
$$f(x) = \int_0^x g(t)\,dt$$
is well-defined and continuously differentiable.
Furthermore, $f(x) \equiv 0$ on every interval $\left[n, n+\frac{1}{2} - \frac{2}{5^n}\right]$, and $f(x) \equiv 1$ on every interval $\left[n+\frac{1}{2}-\frac{1}{5^n}, n+\frac{1}{2}+\frac{1}{5^n}\right]$. Thus on
$$X = \bigcup_{n=1}^\infty \left(\left[n, n+\frac{1}{2} - \frac{2}{5^n}\right] \cup \left[n+\frac{1}{2}-\frac{1}{5^n}, n+\frac{1}{2}+\frac{1}{5^n}\right]\right)$$
we have $f' \equiv 0$, so the derivative is bounded, but
$$f\left(n+\frac{1}{2}-\frac{1}{5^n}\right) - f\left(n+\frac{1}{2}-\frac{2}{5^n}\right) = 1$$
for all $n$, while the distance between the two points is $5^{-n}$ which becomes arbitrarily small, so $f$ is not uniformly continuous on $X$.
If the sentence
Note that $X$ cannot be an interval, a disjoint union of intervals, nor can it be a discrete set.
was meant to forbid a construction as above where $X$ is a disjoint union of intervals, we can obey the letter of the law (but not the spirit) by adding an arbitrary subset of $(-\infty,0)$ that is not a union of disjoint intervals.
Any continuous function on a closed and bounded interval $[a,b]$ is integrable. Since, $f$ is given to be continuously differentiable, its derivative is continuous on the domain, and hence integrable.
If you only want to assume that $f'$ is continuous on $(a,b)$ then it is not so simple. Consider the function $f : [0,1] \to \mathbb{R}$ defined by
$$
f(x) = \begin{cases}
0, & x=0;\\
x^2 \sin (1/x^2), & x \neq 0.
\end{cases}
$$
It is differentiable everywhere, and its derivative is continuous on $(0,1)$, but the derivative is unbounded as $x \to 0^+$. You can take a look at the answers to this question for more examples of bounded functions with unbounded derivatives: Can the graph of a bounded function ever have an unbounded derivative?
Best Answer
Edit: there are indeed differentiable functions with bounded derivative that still fail to attain extrema.
For example
$$ f(x) := \begin{cases} x^2(x-1) \sin (1 /x) & \text{ if } 0<x\leq 1\\ 0 & \text{ if } x= 0 \end{cases} $$ has derivative
$$ f'(x) := \begin{cases} (3x^2-2x) \sin (1 /x) - (x-1)\cos(1/x)& \text{ if } 0<x\leq 1\\ 0 & \text{ if } x= 0 \end{cases}. $$
As $x\searrow 0$ the maxima and minima tend to $\pm 1$ but can never attain it. See graph below ($f$ on the left; $f'$ on the right). And you can play around with the exponent and the other term to create different envelopes, of course.
Original: adapted from Pugh's Real Mathematical Analysis, p.157: Consider $$ f(x) := \begin{cases} x^{3 /2} \sin (1 /x) & \text{ if } 0<x\leq 1\\ 0 & \text{ if } x= 0 \end{cases} $$ whose derivative is $0$ at $x=0$ and $$ f'(x) = \frac{3}{2}\sqrt{x} \sin (1 /x) - \frac{1}{\sqrt{x}}\cos (1 /x) \qquad \text{for } x \neq 0. $$ That $1 /\sqrt{x}$ blows up.