X <- mean(X) is changing the definition of X so that instead of holding your sample values, it now just holds the single mean value.
You can use mean(X) anywhere you want without assigning a name to it. For example:
mean(X) * 2
will print twice whatever the mean of X is to the console.
If you want to give mean(X) a name (so that it appears as an object in your environment that you can re-use), you should give it a new name, e.g.
mean_X <- mean(X)
Running mean(X) on its own shouldn't affect any other code — it just prints the result to the console. If, however, you've used X <- mean(X) to redefine X as the mean instead of the sampled values, then yes, that will affect any other lines of code that refer to X.