Improve file handling of the file consumer type

Instead of opening the file during Analytics::init(), which may happen some
time before the actual writing, we now open, append and close the file
atomically in write() by using file_put_contents() with an exclusive file
lock.

This ensures that the file is open for a shorter amount of time, i.e. in cases
where Analytics::init() is done in some middleware and the actual analytics
calls are done after somewhat time-consuming operations.