I found a workaround. Since writeVideo can't append frames to a closed video file, (in my case) closing video in an appropriate step solves the problem. For example,
for bin=1:n % An individual bin contains a number of frames say 1K
finish=some other calculation;
% Video object is not closed here
Thank for help.