Is there a function $f:[0,\infty) \to \{-1, 1\}$ such that $\int_0^\infty{f(x)\,dx}$ is well defined? I suspect it is impossible to find such an $f$, but I can see one way it might be possible to as well.
If it is possible to construct two sets $A$ and $B$ which partition the non-negative reals such that $A \cap [0,a)$ and $B \cap [0,a)$ both have measure $a/2$ for any positive real $a$, then take $f^{-1}(1) = A$, $f^{-1}(-1) = B$. We would have $\int_0^a{f(x)\,dx}=0$ for all $a$ and $\lim_{a \to \infty}\int_0^a{f(x)\,dx}=0$.
 A: It is possible as an improper integral. Fix a conditionally convergent series $\sum_{n=1}^{\infty} a_n$, and let $T_n = \sum_{k=1}^{n} |a_k|$. Then define $f$ as
$$ f(x) = \operatorname{sgn}(a_n) \qquad\text{whenever}\quad x \in [T_{n-1}, T_n). $$
Then it follows that
$$ \int_{T_{k-1}}^{T_k} f(t) \, \mathrm{d}t
= \int_{T_{k-1}}^{T_k} \operatorname{sgn}(a_k) \, \mathrm{d}t
= \operatorname{sgn}(a_k)(T_k - T_{k-1})
= a_k. $$
So, whenever $x \in [T_n, T_{n+1})$, we get
\begin{align*}
\left| \int_{0}^{x} f(t) \, \mathrm{d}t - \sum_{k=1}^{n} a_k \right|
= \left| \int_{T_n}^{x} f(t) \, \mathrm{d}t \right|
\leq a_{n+1},
\end{align*}
and this converges to $0$ as $n \to \infty$. Therefore,
$$ \int_{0}^{\infty} f(t) \, \mathrm{d}t = \sum_{k=1}^{\infty} a_k. $$
A: Choose a sequence $u_n \ge 0$ such that $u_n \to 0$ but $\sum u_n = \infty$ nonetheless, for example $u_n = 1/n$.  Then, starting at $0 \in [0,\infty)$, define $f$ as $+1$ on an interval of length $u_1$, then as $-1$ on an interval of length $u_1$ again; then repeat, $+1$ for a length of $u_2$ and $-1$ for a length of $u_2$, etc.  Such an $f$ solves your problem for the improper Riemann/Lebesgue integral, as deviations of the integral from $0$ will be under $u_n \to 0$.  Formally, with the partial sums $S_n = \sum_{k<n} u_k$:
$$
f(x) = \begin{cases}
    +1 & \text{for } 2S_n \le x < 2S_n + u_n , \\
    -1 & \text{for } 2S_n + u_n \le x < 2S_{n+1} .
\end{cases}
$$
A: For $x\geqslant0$, define
$$f(x) := \begin{cases}
    1 & \text{if }\; 2^x-\lfloor 2^x\rfloor<\frac12, \\
    -1 & \text{otherwise}.
\end{cases}$$
Then $\int_0^xf(t)\,\mathrm dt$ tends to a limit exponentially fast as $x\to\infty$.
Edit note: The initial version was unnecessarily complicated.
