I can only tell you that long thing looks like a broken down roundworm, which I have seen many times. You must be doing something to expel it, maybe something in you diet that you don't realize.
The good news is now you may have found an answer to digestive issues or other issues you may have been having, the bad news is that it's a long journey and you need to find what works for you to get rid of it.