This is a homework problem for me so please do not post a full solution. I would very much appreciate a hint to move me past the point at which I'm stuck. Here is my work so far:
The setting is that $X$ is an affine algebraic variety over an algebraically closed field $k$ and $U$ is an open affine subvariety. At first I thought that $k[U]$ would necessarily be a localization of $k[X]$ and then it would automatically be flat. Then I learned (e.g. see Hailong Dao's example here) that this doesn't have to be so because a function on $k[U]$ could be locally a quotient of functions in $k[X]$ at every point of $U$ without being a quotient globally on all of $U$.
However, flatness is a very local property, so this shouldn't be a terminal problem. At each point of $U$, $k[U]$ is a localization of $k[X]$. Here's what came out when I tried to make this thought precise: $k[U]$ is flat over $k[X]$ if $k[U]_\mathfrak{m}$ is flat over $k[X]_\mathfrak{m}$ for all maximal ideals $\mathfrak{m}$ of $k[X]$. Now if $\mathfrak{m}$ corresponds to a point $p$ of $X$ that is in $U$, then $k[U]_\mathfrak{m}=k[X]_\mathfrak{m}=\mathcal{O}_{X,p}$. Since any ring is flat over itself, for $\mathfrak{m}$ corresponding to $p\in U$, we have what we need.
This also seems to be the argument given by James Milne in his notes (see p. 146, footnote 1). However, I am unsatisfied. To apply the theorem that flatness is local, I need to localize at every maximal ideal of the base ring, which in this case is $k[X]$. I localized at all $\mathfrak{m}$ corresponding to $p\in U$; but what about the maximal ideals of $k[X]$ corresponding to points outside $U$? Is it obvious that $k[U]_\mathfrak{m}$ is flat over $k[X]_\mathfrak{m}$ in these cases?
I have gotten as far as trying to describe the rings $k[U]_\mathfrak{m}$ and $k[X]_\mathfrak{m}$ to myself in these cases. $k[U]_\mathfrak{m}$ is functions regular on $U$ divided by functions nonzero at $p\notin U$. $k[X]_\mathfrak{m}$ is functions regular on all of $X$ divided by functions nonzero at $p$. This can now be a smaller ring, so it is no longer any more clear to me that $k[U]_\mathfrak{m}$ is flat over $k[X]_\mathfrak{m}$ than it was that $k[U]$ was flat over $k[X]$ in the first place. This is where I'm stuck.
Further thoughts: although I haven't seen so far how to make this local proof work, the basic logic of working locally seems inescapable to me: after all, $k[U]$ consists of quotients of functions from $k[X]$. Shouldn't it be flat for "essentially the same reason" that localizations are flat?
At any rate, a hint to push me past this stuck point would be much appreciated. Thanks in advance.