Considering what you are doing, won’t using memcached be a better option?
You just store your ips as key=value pairs in memcached, with an expiry of 5 minutes. Thus your data always expires every 5 minutes.
Also interaction with memcached is much easier than file-handling.
2
solved How to delete a .txt file after a certain time? [closed]