It is not at all clear what you are trying to do in that long piece of code, even after I completely untangled the code.
Computing a plane orthogonal to a line is a trivial thing to do however, but all depends on what you intend to do with it. A plane is spanned by two vectors, orthogonal to the line. We can get such a pair of vectors using null.
P1 = rand(1,3)
0.91338 0.63236 0.09754
P2 = rand(1,3)
0.2785 0.54688 0.95751
V = null(P1 - P2)
So the columns of V are vectors orthogonal to that line.
We can write any point that lies in the plane as some linear combination of those two vectors, plus some specific point in the plane. So if X0 is a point in the plane, then the equation of the plane is
What you actually want to do in that mess of code, that I have no idea.