Only flush sessions if they are dirty

Adds an 'is_dirty' attribute and only flushes the session if the session
is marked dirty.  This avoids unnecessary writes of unchanged data.
perltidy some files