Yes it's an idiom, a bit old-fashioned and means suddenly, unexpectedly, without any reason e.g:
Przez chwilę stał spokojnie, ale nagle, ni z gruszki, ni z pietruszki, zaczął uciekać.
You can use nagle, nieoczekiwanie or bez powodu instead of this phrase.