Incorrect Butterworth filter outcome using Rational Transfer Funcion
The output can be calculated using the coefficients as follows:

$$a_0y(n)+a_1y(n-1)+a_2y(n-2)=b_0x(n)+b_1x(n-1)+b_2x(n-2)$$

In your formula you are not doing this. Instead, you are doing a division with terms that only involve the input and not the output, which doesn't make sense as the filter is IIR.

I suspect that you got confused with the transfer function definition of an IIR filter, which is given by

$$H(z)=\frac{Y(z)}{X(z)}=\frac{\sum\limits_{k=0}^2 b_kz^{-k}}{\sum\limits_{k=0}^2 a_kz^{-k}}$$

Note that you are using an equation in the $z$-domain applied to time-domain signals (to put it simply). That's why the loop you wrote is not working.