Alright guys, I think I've solved the problem. In the end, the problem was not fault of opengl. It was just my sloppy string conversion in the loadShader function that created the randomness.
The readFile function reads the input to stringstream and returns a string inputStream.str(). In the loadFromFile function the shader code was received like this: const GLchar *shaderCode = readFile(filename).c_str(); This line is the root of the problem. It depends on luck how it gets the data into GLchar *shaderCode. This additional line fixes the problem:
Code :
std::string temp = readFile(filename);
GLchar *shaderCode = temp.c_str();

I'm grateful for Silence for pointing me to the right direction, thank you.