First of all: What does it mean that a function is dense? I know what a dense set is, but what's a dense function?
Proof for f $\ge$ 0, for the rest it's analogical
Let's say, that $E_k = f^{-1} \text{[} k2^{-n}, (k+1)2^{-n})$
For the proof, we use the Monotone Convergence Theorem.
If $\phi_n = \sum_{k}^{n2^n} (\frac{k}{2^n}\cdot\mathbf{1}_{E_k}+ n\cdot\mathbf{1}_{\left\{ x \: : \: f(x) > n \right\}})$, then we have: $$\int |f|^p \ge \int |f - \phi_n|^p \rightarrow 0$$
What I don't understand is how does this prove that our function $f$ is dense? It just proves that the integral of f taken to the p-th power is greater/equal than 0. Nothing more.
Also, why do we define our $E_k$ in such a specific way? What if they're not like that? Would the prove still hold?
The statement is : the set of simple functions is dense in $L^p$. The proof you gave shows the case $p = 1$. In fact the proof is:
Assume $f \in L^1$ is non negative. Then set $$ \phi_n = \left( \sum_{k=0}^{2^n-1} \frac{k}{2^n}\cdot\mathbf{1}_{E_k} \right)+ n\cdot\mathbf{1}_{\left\{ x \: : \: f(x) > n \right\}} $$ which is a non-decreasing sequence of positive simple functions with pointwise limit $f$. By the monotone convergence theorem (Beppo-Levi lemma) you have that $$ \int_X \phi_n d \mu \rightarrow \int_X f d\mu $$ and thus $$ ||f-\phi_n||_{L^1} = \int_X |f-\phi_n|d\mu = \int_Xfd\mu - \int_X \phi_nd\mu \rightarrow0. $$
The $E_k$ are taken is such a way that they partition $X$, on each $E_k$ $\phi_n$ approaches $f$ by taking one of its value and the size of each $E_k$ goes to 0. Hence $\phi_n$ approaches $f$.
Of course if you choose randomly your $E_k$ your sequence have no chance to approach $f$. For instance take $E_k = \emptyset$ and $f \neq 0$.