I switched over to storing them into a db as done in the book but I notice that when my code has errors, often it leads to an error in the write_session() function. Calling on a function on a non-object, $dbc. The funny thing is that there is no code to write to the session but there is code to read session data.
It appears to be trying to write a session before opening the session and establishing a db connection. I confirmed it by putting code inside the write_session() function to open a new connection at each call.