Mac Application to defrag my Mac drive
Speed of access on HFS+ drives is not that affected by fragmentation unlike Windows file systems as OSX will do some defragmentation. A third party investigation is here.

You might be better off checking there is enough free space for new files.

There are some utilities to do defragmentation like iDefrag