All windows loses focus every 5 minutes
You can use the following Python script which can tell you which app is currently on focus:

#!/usr/bin/python
# Prints current window focus.
# See: https://apple.stackexchange.com/q/169277
from AppKit import NSWorkspace
import time
workspace = NSWorkspace.sharedWorkspace()
active_app = workspace.activeApplication()['NSApplicationName']
print('Active focus: ' + active_app)
while True:
    time.sleep(1)
    prev_app = active_app
    active_app = workspace.activeApplication()['NSApplicationName']
    if prev_app != active_app:
        print('Focus changed to: ' + active_app)


It will print active application which has the focus and any change every second.

Related script: Identify which app or process is stealing focus on OSX at Gist

Usage:


Save above script into get_active_focus.py file.
Assign execution attributes by: chmod +x get_active_focus.py command.
Run it as: ./get_active_focus.py.


Output:

$ ./get_active_focus.py
Active focus: Terminal
Focus changed to: Google Chrome




Once you found the affected application, consider uninstalling or killing it (if possible).