Fix period deletion and lock

Hi perlancer.

This patch fixes the following bugs.

1. "rotate by period" never deleted old files.
2. The lock file remained if write() method died for some reason.

To fix these bugs, I added some tests and added/removed some private methods. Please see the commit logs for detail.