We say that for a topological space $X$, $\mathcal{O}_X$ is a pre-sheaf if for all open $U\subseteq X$, $\mathcal{O}_X(U)$ is a ring, $\mathcal{O}_X(\varnothing)=0$, and if we have defined $\forall\ U\subseteq V$ the restriction homomorphisms $\rho_{V,U}:\mathcal{O}_X(V)\to\mathcal{O}_X(U)$ s.t. $\rho_{U,U}=\mathrm{id}$, $U\subseteq V\subseteq W\implies \rho_{W,U}=\rho_{V,U}\circ\rho_{W,V}$. For convenience, given $f\in V$, we write $\rho_{V,U}(f)=f|_U$.
$\mathcal{O}_X$ is called a sheaf if whenever $U\subseteq X$ is open, $\{U_i\}_i$ is an open cover for $U$, and $f_i\in\mathcal{O}_X(U_i)\ \forall\ i$ s.t. $f_i|_{U_i\cap U_j}=f_j|_{U_i\cap U_j}\ \forall\ i,j$, then $\exists!\ f\in U$ s.t. $f|_{U_i}=f_i\ \forall\ i$.
This defines the pair $(X,\mathcal{O}_X)$, which we call a ringed space.
If $X\subseteq\mathbb{A}^n_k$ is an affine variety, then $\mathcal{O}_X$ is said to be the structure sheaf when $\mathcal{O}_X(U)$ is the set of $k$-valued regular functions on $U$. It can be shown that this defines a sheaf, with the restriction map.
More generally, given any irreducible topological space $X$, and any sheaf $\mathcal{O}_X$ of $k$-valued functions s.t. $X$ is homeomorphic to some (irreducible) affine variety in $\mathbb{A}^n_k$, we say that the ringed space $(X,\mathcal{O}_X)$ is an affine variety.
My question is, why do we do this? It seems to me that we could simply define $\mathcal{O}_X(U)=0\ \forall\ U$, i.e. $f\in\mathcal{O}_X(U)\implies f(u)=0\ \forall\ u\in U$, defined on any affine variety $X\subseteq\mathbb{A}^n_k$. We could also define $\mathcal{O}_X(U)=k^U\ \forall\ U$, which would be similarly meaningless. Does $\mathcal{O}_X$ have any meaning as a structure sheaf in this generalized context?
This is not the standard definition of "affine variety". The standard definition would require not just that $X$ is homeomorphic to an affine variety in $\mathbb{A}^n_k$ but that it is isomorphic to an affine variety $Y$ in $\mathbb{A}^n_k$ as a ringed space. That is, there is a homeomorphism $f:X\to Y$ such that the induced map of sheaves of rings $f^*\mathcal{O}_Y\to\mathcal{O}_X$ is an isomorphism.
Indeed, your definition allows many exotic things that no one normally considers to be "affine varieties". Besides the examples you named, note also that any irreducible projective curve is homeomorphic to $\mathbb{A}^1$, and so every such curve would be considered "affine" by this definition.